package com.bt.controller.admin;

import com.bt.dto.YddUserDTO;
import com.bt.dto.YddUserPageQueryDTO;
import com.bt.entity.YddUser;
import com.bt.result.PageResult;
import com.bt.result.Result;
import com.bt.service.YddUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author 锟
 * @Date 2023-04-29 16:30
 */

/**
 * 会员管理
 */
@Api(tags = "会员管理相关接口")
@RestController
@RequestMapping("/ydd_user")
@Slf4j
public class YddUserController {

    @Autowired
    private YddUserService yddUserService;

    /**
     * 会员新增
     * @param yddUserDTO
     * @return
     */
    @ApiOperation("新增会员接口")
    @PostMapping("/add")
    public Result add(@RequestBody YddUserDTO yddUserDTO){
        System.out.println("YddUserController的add方法线程id:"+Thread.currentThread().getId());
        log.info("新增会员接口:{}", yddUserDTO);

        //调用会员新增接口
        yddUserService.add(yddUserDTO);

        //返回数据
        return Result.success();
    }

    /**
     * 会员分页查询
     * @param yddUserPageQueryDTO
     * @return
     */
    @ApiOperation("会员分页查询接口")
    @GetMapping("/list")
    public Result list(YddUserPageQueryDTO yddUserPageQueryDTO){
        log.info("会员分页查询接口:{}",yddUserPageQueryDTO);

        //调用分页查询接口数据
       PageResult pageResult = yddUserService.list(yddUserPageQueryDTO.getPage(),
               yddUserPageQueryDTO.getLimit(), yddUserPageQueryDTO.getUsername(),
               yddUserPageQueryDTO.getMobile(),yddUserPageQueryDTO.getSex());

       //返回数据
        return Result.success(pageResult);
    }

    /**
     * 根据id查询会员回显接口
     * @return
     */
    @ApiOperation("根据id查询会员回显接口")
    @GetMapping("/rowInfo")
    public Result findById(Integer id){
        log.info("根据id查询会员回显接口:{}",id);

        //调用业务根据id查询会员
       YddUser yddUser = yddUserService.findById(id);

       //返回数据
        return Result.success(yddUser);
    }


    /**
     * 会员修改接口
     * @param yddUserDTO
     * @return
     */
    @ApiOperation("会员修改接口")
    @PostMapping("/update")
    public Result update(@RequestBody YddUserDTO yddUserDTO){
        log.info("会员修改接口",yddUserDTO);

        //调用业务修改会员
        yddUserService.update(yddUserDTO);

        //返回结果
        return Result.success();
    }

    /**
     * 会员删除
     */
    @ApiOperation("会员删除接口")
    @GetMapping("/del")
    public Result delete(Long id){
        log.info("删除会员:{}",id);

        //删除指定数据
        yddUserService.delete(id);

        //返回数据
        return Result.success();
    }

}
